package ${baseInfo.packageName};

import com.fa4j.common.base.model.RemoveCmd;
import ${converter.packageName}.${converter.fileName}Impl;
import ${domain.packageName}.${domain.fileName};
import ${createCmd.packageName}.${createCmd.fileName};
import ${modifyCmd.packageName}.${modifyCmd.fileName};
import ${repositoryInterface.packageName}.${repositoryInterface.fileName};


import ${serviceInterface.packageName}.${serviceInterface.fileName};


import com.github.jsonzou.jmockdata.JMockData;
import com.github.jsonzou.jmockdata.MockConfig;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.bean.override.mockito.MockitoBean;

import java.util.Optional;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@Slf4j
@DisplayName("${tableClass.remark}")
@Import(${converter.fileName}Impl.class)
@SpringBootTest(classes = ${serviceInterface.fileName}Impl.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
class ${baseInfo.fileName} {

    @Autowired
    private ${serviceInterface.fileName} ${serviceInterface.fileName?uncap_first};

    @MockitoBean
    private ${repositoryInterface.fileName} ${repositoryInterface.fileName?uncap_first};


    @Test
    @DisplayName("新增")
    void create() {
        ${createCmd.fileName} cmd = JMockData.mock(${createCmd.fileName}.class);
        ${serviceInterface.fileName?uncap_first}.create(cmd);
        verify(${repositoryInterface.fileName?uncap_first}).create(any());
    }

    @Test
    @DisplayName("编辑")
    void modify() {
        ${domain.fileName} mockData = JMockData.mock(${domain.fileName}.class);
        when(${repositoryInterface.fileName?uncap_first}.findById(mockData.getId())).thenReturn(Optional.of(mockData));
        ${modifyCmd.fileName} cmd = JMockData.mock(${modifyCmd.fileName}.class, new MockConfig().excludes("id"));
        cmd.setId(mockData.getId());
        ${serviceInterface.fileName?uncap_first}.modify(cmd);
        verify(${repositoryInterface.fileName?uncap_first}).modify(mockData);
    }

    @Test
    @DisplayName("删除")
    void remove() {
        ${domain.fileName} mockData = JMockData.mock(${domain.fileName}.class);
        when(${repositoryInterface.fileName?uncap_first}.findById(mockData.getId())).thenReturn(Optional.of(mockData));
        ${serviceInterface.fileName?uncap_first}.remove(RemoveCmd.of(mockData.getId(), 0L));
        verify(${repositoryInterface.fileName?uncap_first}).remove(mockData);
    }
}